<!-- 存货周转率 -->
<template>
  <div class="app-container">
    <div class="search-and-button1" :class="{ showSearch: show }">
      <ImportFile url="/wms/statistics/summary/import" @getTableInfo="getTableInfo" />
      <el-button type="primary" plain :icon="!show ? 'el-icon-arrow-down' : 'el-icon-arrow-up'" @click="show = !show">查询条件</el-button>
      <el-button type="primary" icon="el-icon-search" @click="getTableInfo()">查询</el-button>
    </div>
    <transition name="el-zoom-in-top">
      <div v-show="show" class="more-search">
        <el-form :model="search" label-width="80px">
          <el-row>
            <el-col :xs="24" :xl="6" :md="12">
              <el-form-item label="日期" prop="searchDate">
                <el-date-picker v-model="search.searchDate" @change="getTableInfo()" type="month" placeholder="选择月"></el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </div>
    </transition>
    <el-row class="table">
      <el-table v-loading="loading" :data="tableData" ref="tableData" stripe border>
        <el-table-column type="selection" align="center"></el-table-column>
        <el-table-column align="center" type="index" label="索引" width="60px" />
        <el-table-column v-for="item in fields" v-if="!item.val.includes('（')" :align="item.align || 'left'" :prop="item.code.split(':')[1]" :label="item.val" :min-width="item.width + 'px'" />
        <el-table-column label="本期收入" align="center">
          <el-table-column v-for="item in fields" v-if="item.val.includes('本期收入')" :align="item.align || 'left'" :prop="item.code.split(':')[1]" :label="item.val.replace(/本期收入|（|）/g, '')" :min-width="item.width + 'px'" />
        </el-table-column>
        <el-table-column label="本期发出" align="center">
          <el-table-column v-for="item in fields" v-if="item.val.includes('本期发出')" :align="item.align || 'left'" :prop="item.code.split(':')[1]" :label="item.val.replace(/本期发出|（|）/g, '')" :min-width="item.width + 'px'" />
        </el-table-column>
        <el-table-column label="本期结存" align="center">
          <el-table-column v-for="item in fields" v-if="item.val.includes('本期结存')" :align="item.align || 'left'" :prop="item.code.split(':')[1]" :label="item.val.replace(/本期结存|（|）/g, '')" :min-width="item.width + 'px'" />
        </el-table-column>
        <el-table-column label="上期结存" align="center">
          <el-table-column v-for="item in fields" v-if="item.val.includes('上期结存')" :align="item.align || 'left'" :prop="item.code.split(':')[1]" :label="item.val.replace(/上期结存|（|）/g, '')" :min-width="item.width + 'px'" />
        </el-table-column>
      </el-table>
    </el-row>

    <el-row>
      <div class="table-btn-box">
        <el-button @click="
            () => {
              tableData.forEach(row => {
                $refs['tableData'].toggleRowSelection(row, true)
              })
            }
          ">选择全部</el-button>
        <el-button @click="
            () => {
              tableData.forEach(row => {
                $refs['tableData'].toggleRowSelection(row)
              })
            }
          ">反向选择</el-button>
        <el-button>
          更多菜单
          <i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
      </div>
      <pagination ref="Pagination" :total="total" :current.sync="search.current" :size.sync="search.size" @pagination="getTableInfo" />
    </el-row>
  </div>
</template>
<script>
import ImportFile from '@/components/ImportFile'
import Pagination from '@/components/Pagination'
import { timeFormatToString } from '@/utils/function'
export default {
  components: { Pagination, ImportFile },
  props: {
    fields: {
      type: Array,
      default: []
    }
  },
  data() {
    return {
      loading: false,
      tableData: [],
      total: 0,
      search: {
        current: 1,
        size: 20,
        keyword: '',
        beginDate: '',
        endDate: '',
        searchDate: timeFormatToString(new Date()).slice(0, 7),
        objNo: '',
        time: [],
        treeStr: '-1'
      },
      materialList: [],
      userAllList: [],
      show: false
    }
  },
  mounted() {
    this.getTableInfo()
  },

  methods: {
    getInfo(str) {
      this.search.treeStr = str
      this.getTableInfo(1)
    },
    /**
     * @description: page
     * @param {*} page
     * @return {*}
     */
    async getTableInfo(page = 1) {
      this.search.current = page
      if (this.search.searchDate)
        this.search.searchDate = timeFormatToString(
          this.search.searchDate
        ).slice(0, 7)
      this.loading = true
      const res = await this.$axios.post('/wms/stat/summary', this.search)
      if (res?.data.code === 200) {
        this.tableData = res.data.data.list
        this.total = res.data.data.total
        setTimeout(() => {
          this.loading = false
        }, 100)
      } else {
        this.loading = false
      }
    }
  }
}
</script>
<style lang='scss' scoped>
.app-container {
  padding: 0px;
}
.search-and-button1 {
  min-height: 33px;
  line-height: 30px;
  height: 30px !important;
  overflow: hidden;
  transition: height 0.3s;
  width: 100%;
  .el-input {
    width: 350px;
    float: right;
  }
}
.table {
  margin-top: 10px;
}
</style>
